package 
{
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.StageScaleMode;
	import flash.net.URLRequest;
	
	import com.linh.events.video.VideoControlsEvent;
	import com.linh.ui.video.ApdevVideoPlayer;
	
	/**
	 * ...
	 * @author linhtv
	 */
	public class Main extends Sprite 
	{	
		public function Main():void 
		{
			// adjust stage's scalemode
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			// create videoplayer
			var video:ApdevVideoPlayer = new ApdevVideoPlayer(590, 330);
			
			// position videoplayer on stage
			video.x = stage.stageWidth/2 - video.width/2;
			video.y = stage.stageHeight/2 - video.height/2;
			// add videoplayer to stage
			addChild(video);
			
			// add eventlistener
			video.addEventListener(VideoControlsEvent.STATE_UPDATE, onStateUpdate, false, 0, true);
			
			// position the videoplayer's controls at the bottom of the video
			video.controlsOverVideo = true;
			// controls should not fade out (when not in fullscreen mode)
			video.controlsAutoHide = true;
			// load preview image
			video.videostill = "videostill.jpg";
			// set video's autoplay to false
			video.autoPlay = false;
			// load video
			video.load("test.flv");
		}
		
		/**
		 * event listener - called when videoplayer's state changes.
		 */
		private function onStateUpdate(event:VideoControlsEvent):void
		{
			trace("onStateUpdate() >>> " + event.data);
		}
		/*private var _loader:Loader;
		
		public function Main():void 
		{
			_loader = new Loader();
			addChild(_loader);
			
			_loader.x = 25;
			_loader.y = 25;
			_loader.load(new URLRequest("videostill.jpg"));
			
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoader);
		}
		
		private function onLoader(event:Event):void {
				var bitmap:BitmapData = new BitmapData(_loader.width, _loader.height);
				//bitmap.draw(_loader);
				var shapeObj:Sprite = new Sprite();
				shapeObj.graphics.lineStyle();
				shapeObj.graphics.beginBitmapFill(bitmap);
				shapeObj.graphics.endFill();
				addChild(shapeObj);
		}*/
		

		
	}
	
}